//
//  TTNewStyleController.m
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/24.
//  Copyright © 2016年 陶路路. All rights reserved.
//

#import "TTNewStyleController.h"
#import "TTNewStyleCell.h"
@interface TTNewStyleController ()<UICollectionViewDataSource>

@property (nonatomic,strong) UICollectionView * collection;

@property (nonatomic,strong) UICollectionViewFlowLayout * layout;

@end

@implementation TTNewStyleController


-(UICollectionView *)collection{
    
    if (_collection == nil) {
        
        self.layout = [[UICollectionViewFlowLayout alloc]init];
        
        _collection = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.layout];
        
        _collection.dataSource = self;
    }
    
    return _collection;
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self.view addSubview:self.collection];
    
    [self setUpUI];
    
    [self.collection registerClass:[TTNewStyleCell class] forCellWithReuseIdentifier:@"collection"];
}


-(void)setUpUI{
    
    [self.collection mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.view);
    }];
    
    self.layout.minimumInteritemSpacing = 0;
    self.layout.minimumLineSpacing = 0;
    self.layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collection.pagingEnabled = YES;
    self.collection.bounces = NO;
}

-(void)viewDidLayoutSubviews{
    
    [super viewDidLayoutSubviews];
    
    self.layout.itemSize = self.collection.bounds.size;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 4;
}

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    TTNewStyleCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collection" forIndexPath:indexPath];
    
    if (cell == nil) {
        
        cell = [[TTNewStyleCell alloc]init];
    }
//    cell.backgroundColor = RANDOMCOLOR;
    cell.index = indexPath.item;
    
    return cell;
}
@end
